<?php

namespace app\common\service\cash;

use app\common\enum\user\UserCashPayTypeEnum;
use app\common\model\settings\Setting;

/**
 * 现金服务
 * Class AwardService
 * buyer 买家userModel
 * ind_set 单独奖励设置
 */
class CashService
{
    //是否可以提现
    public static function ableWithdraw($user, $param)
    {
        if (!$user) {
            return [
                "status" => false,
                "msg" => "用户不存在"
            ];
        }
        $app_id = $user['app_id'];
        $setting = Setting::getItem('balance_cash', $app_id);
        if (!$setting['is_open']) {
            return [
                "status" => false,
                "msg" => "提现功能未开启"
            ];
        }
        $money = $param['money'] ?? 0;
        if ($money <= 0) {
            return [
                "status" => false,
                "msg" => "提现金额必须大于0"
            ];
        }
        if ($setting['min_amount'] > 0 && $money < $setting['min_amount']) {
            return [
                "status" => false,
                "msg" => "提现金额不能小于" . $setting['min_amount']
            ];
        }
        $pay_type = $param['pay_type'] ?? UserCashPayTypeEnum::WX;
        if (!in_array($pay_type, $setting['cash_type'])) {
            return [
                "status" => false,
                "msg" => "暂不支持此提现方式"
            ];
        }
        if ($user['balance'] < $money) {
            return [
                "status" => false,
                "msg" => "用户可提现余额不足"
            ];
        }
        return [
            "status" => true,
            "msg" => "可以提现"
        ];
    }
}